package com.pimee.web.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.pimee.common.config.UbConfig;
import com.pimee.common.constants.Constants.File;

/**
 * web拦截器配置
 * @author Bruce Shaw
 * 2020年2月3日 上午11:46:53
 *
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

	private static final String EXCLUDE_PATH = "\"\", \"/login.html\", \"/admin/login\",\"/**/css/**\", \"/**/js/*\", \"/**/ajax/**\", \"/**/file/**\",\"/**/ruoyi/**\", \"/**/*.png\", \"/**/fonts/*\", \"/**/i18n/*\", \"/**/*.ico\"";
	
	/**
	 * 拦截器配置
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new EventInterceptor()).addPathPatterns("/**")
		.excludePathPatterns(EXCLUDE_PATH);

		// 注意，拦截器配置不能使用配置文件的统一api路径配置：server.servlet.context-path，这样配置是无效的。
		// 只能使用controller里面的具体路径配置，才能有效拦截
		// registry.addInterceptor(apiAccessInterceptor).addPathPatterns("/play/api/**");

	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		/** 本地文件上传路径 */
		registry.addResourceHandler(File.RESOURCE_PREFIX + "/**")
				.addResourceLocations("file:" + UbConfig.getProfile() + "/");

		/** swagger配置 */
		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
	}
}